home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources-Apple / driver.c next >
Encoding:
C/C++ Source or Header  |  1993-07-02  |  23.2 KB  |  922 lines  |  [TEXT/MPS ]

  1. /*
  2.     driver program for mpw native gcc compiler
  3.     
  4.   Copyright (C) 1990, 1992 Apple Computer, Inc.
  5.     
  6.     Written by:
  7.         Larry Rosenstein
  8.         Brent H. Pease
  9.     
  10.     
  11.     Accepts most MPW C command line arguments and transforms them into gcc arguments.
  12.     Issues warnings for MPW C command arguments that are NOT supported
  13.     Accepts certain GCC C command arguments that do not conflict with MPW C
  14. */
  15.  
  16. #include <types.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #define MAXFILENAME 255
  22.  
  23. int    run_cpp = 1;
  24. int run_cc1 = 1;
  25. int run_asm = 1;
  26. int optimize = 1;
  27. int quiet_flag = 1;
  28. int echo_cmds = 0;
  29. int make_short = 0;
  30. int got_mc68020 = 0;
  31. int got_mc68040 = 0;
  32. int debug_gcc = 0;
  33. int overlay_strings = 0;
  34. int warn_dash_m_flag = 0;
  35.  
  36. char* output_filename;
  37. char* input_filename;
  38. char* tool_place;
  39. char* tmp;
  40.  
  41. char *cpp_options;
  42. char *cc1_options;
  43. char *asm_options;
  44.  
  45. char *target_name = "Mac68K";
  46.  
  47. char *asm_tool_name = "Asm";
  48.  
  49. char tmp_filename[MAXFILENAME];
  50. char cpp_filename[MAXFILENAME];
  51. char asm_filename[MAXFILENAME];
  52. char out_filename[MAXFILENAME];
  53. char *shorten_filename = "•••asm_warnings•••";
  54. char *shorten_out_filename = "•••asm_modified•••";
  55.  
  56. /*Handle the sym options notypes, nolines, novars*/
  57. int HandleSymOpts(char *pOpt) {
  58.     register char *ptr = pOpt;
  59.     
  60.     while(1) {
  61.         /*Check for notypes*/
  62.         if (strncmp(ptr, "notypes", 7) == 0) {
  63.             warn_not_implemented("notypes");
  64.             ptr += 7;
  65.         
  66.         /*Check for nolines*/
  67.         } else if (strncmp(ptr, "nolines", 7) == 0) {
  68.             warn_not_implemented("nolines");
  69.             ptr += 7;
  70.         
  71.         /*Check for novars*/
  72.         } else if (strncmp(ptr, "novars", 6) == 0) {
  73.             warn_not_implemented("novars");
  74.             ptr += 6;
  75.         
  76.         /*Check for must not be a sym option*/
  77.         } else {
  78.             return 0;
  79.         }
  80.         if ((*ptr != ',') || (*ptr == 0)) {
  81.             return 1;
  82.         }
  83.         ptr++;
  84.     }
  85. }
  86.  
  87. /*Handle the -opt*/
  88. void HandleOptOpts(char *pOpt) {
  89.     register char *ptr = pOpt;
  90.     
  91.     while(1) {
  92.         /*Check for off(mpwc)*/
  93.         if (strncmp(ptr, "off", 3) == 0) {
  94.             optimize = 0;
  95.             ptr += 3;
  96.         
  97.         /*Check for on(mpwc)*/
  98.         } else if (strncmp(ptr, "on", 2) == 0) {
  99.             optimize = 1;
  100.             ptr += 2;
  101.         
  102.         /*Check for full(mpwc)*/
  103.         } else if (strncmp(ptr, "full", 4) == 0) {
  104.             optimize = 1;
  105.             make_short = 1;
  106.             ptr += 4;
  107.         
  108.         /*Check for nopeep(mpwc)*/
  109.         } else if (strncmp(ptr, "nopeep", 6) == 0) {
  110.             strcat(cc1_options, " -fno-peephole");
  111.             ptr += 6;
  112.         
  113.         /*Check for nocse(mpwc)*/
  114.         } else if (strncmp(ptr, "nocse", 5) == 0) {
  115.             warn_not_implemented("nocse");
  116.             ptr += 5;
  117.         
  118.         /*Check for high(custom)*/
  119.         } else if (strncmp(ptr, "high", 4) == 0) {
  120.             optimize = 2;
  121.             make_short = 1;
  122.             ptr += 4;
  123.         
  124.         /*Check for branch(custom)*/
  125.         } else if (strncmp(ptr, "branch", 6) == 0) {
  126.             make_short = 1;
  127.             ptr += 6;
  128.         
  129.         /*Unknown option*/
  130.         } else {
  131.             fprintf (stderr, "# Warning: unknown option for -opt.\n");
  132.         }
  133.         if ((*ptr != ',') || (*ptr == 0)) {
  134.             return;
  135.         }
  136.         ptr++;
  137.     }
  138. }
  139.  
  140. main (argc, argv)
  141. int argc;
  142. char* argv[];
  143. {
  144.     int i, badopt;
  145.     char* arg, *arg1, *tmp;
  146.     char* missing;
  147.     char* basename;
  148.     
  149.     cpp_options = (char *)malloc(10000);
  150.     cc1_options = (char *)malloc(10000);
  151.     asm_options = (char *)malloc(10000);
  152.     *cpp_options = 0;
  153.     *cc1_options = 0;
  154.     *asm_options = 0;
  155.     
  156.     output_filename = "";
  157.     input_filename = "";
  158.     tool_place = "";
  159.     tmp = ":";
  160.     
  161.     strcpy(cpp_options, "-D__GNUC__=1");
  162.     cc1_options[0] = '\0';
  163.     //strcpy(asm_options, "-w");
  164.     
  165.     for (i=1; i<argc; i++) {
  166.         arg = argv[i];
  167.         badopt = 0;
  168.         missing = "";
  169.         
  170.         if (arg[0] == '-') {
  171.           arg1 = arg;
  172.             switch(arg[1]) {
  173.                 case 'a':
  174.                     /*Check for -ansi(gcc)*/
  175.                     if (strcmp(arg, "-ansi") == 0) {
  176.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  177.                         
  178.                     /*Check for -asm(custom)*/
  179.                     } else if (strcmp(arg, "-asm") == 0) {
  180.                         run_asm = 0;
  181.                     
  182.                     } else if (strncmp(arg, "-aux-info", 9) == 0) {
  183.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  184.                         
  185.                     /*Unknown option*/
  186.                     } else {
  187.                         badopt = 1;
  188.                     }
  189.                     break;
  190.                     
  191.                 case 'b':
  192.                     /*Check for -b(mpwc)*/
  193.                     if (arg[2] == '\0') {
  194.                         strcat(cc1_options, " -mbfun -mbstr");
  195.                     } else if ( arg[2] == '2' && arg[3] == '\0' ) {
  196.                         strcat(cc1_options, " -mbfun -mbstr");
  197.                         overlay_strings = 1;
  198.                     } else if ( arg[2] == '3' && arg[3] == '\0' ) {
  199.                         strcat(cc1_options, " -mbstr");
  200.                         overlay_strings = 1;
  201.                     } else if (strcmp(arg, "-bigseg") == 0) {
  202.                         warn_not_implemented(arg);
  203.                     
  204.                     /*Unknown option*/
  205.                     } else {
  206.                         badopt = 1;
  207.                     }
  208.                     break;
  209.                     
  210.                 case 'c':
  211.                     /*Check for -c(mpwc)*/
  212.                     if (arg[2] == '\0') {
  213.                         run_cc1 = 0;
  214.                     
  215.                     /*Unknown option*/
  216.                     } else {
  217.                         badopt = 1;
  218.                     }
  219.                     break;
  220.                     
  221.                 case 'd':
  222.                     /*Check for -d string(mpwc)*/
  223.                     if (arg[2] == '\0') {
  224.                         if (++i<argc) {
  225.                             char *savepos = cpp_options+strlen(cpp_options);
  226.                             /*transform into gcc command*/
  227.                             strcat(cpp_options, " -D");  strcat(cpp_options, argv[i]);
  228.                             escape_single_quotes(savepos);
  229.                         } else {
  230.                             missing = "symbol";
  231.                         }
  232.                                         
  233.                     } else {
  234.                         /* Probably a debugging option -d<x> - pass thru to cc1 */
  235.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  236.                     }
  237.                     break;
  238.                     
  239.                 case 'e':
  240.                     /*Check for -e(mpwc)*/
  241.                     if (arg[2] == '\0') {
  242.                         /*Transform into gcc argument*/
  243.                         strcat(cpp_options, " -C");
  244.                         run_cc1 = 0;
  245.                     
  246.                     /*Check for -e2(mpwc)*/
  247.                     } else if (arg[2] == '2' && arg[3] == '\0') {
  248.                         run_cc1 = 0;
  249.                     
  250.                     /*Check for -elems881(mpwc)*/
  251.                     } else if (strcmp(arg, "-elems881") == 0) {
  252.                         strcat(cc1_options, " -melems881");
  253.                     
  254.                     /*Unknown option*/
  255.                     } else {
  256.                         badopt = 1;
  257.                     }
  258.                     break;
  259.                     
  260.                 case 'f':
  261.                     /*Check for fx(undocumented)*/
  262.                     if (arg[2] == 'x' && arg[3] == '\0') {
  263.                         /*Make sure there is another option*/
  264.                         if (++i>=argc) {
  265.                             missing = "number";
  266.                         
  267.                         /*Check for 30*/
  268.                         } else if (strcmp(argv[i], "30") == 0) {
  269.                             strcat(cc1_options, " -mfx30");
  270.                         
  271.                         /*Unknown fx argument*/
  272.                         } else {
  273.                             fprintf (stderr, "# Warning: -fx %s ignored.\n", argv[i]);
  274.                         }
  275.                     
  276.                     /*Check for a whole slew of gcc options*/
  277.                     } else if (arg[2] != '\0') {
  278.                         /* pass it on to cc1 and let it complain */
  279.                         strcat(cc1_options, " ");
  280.                         strcat(cc1_options, arg);
  281.                     
  282.                     /*Unknown option*/
  283.                     } else {
  284.                         badopt = 1;
  285.                     }
  286.                     break;
  287.                 
  288.                 case 'i':
  289.                     /*check for -i pathname(mpwc)*/
  290.                     if (arg[2] == '\0') {
  291.                         /*Make sure there are more arguments*/
  292.                         if (++i<argc) {
  293.                             /*Transform into gcc argument*/
  294.                             strcat(cpp_options, " -I'");
  295.                             strcat(cpp_options, argv[i]);
  296.                             strcat(cpp_options, "'");
  297.                         } else {
  298.                             missing = "directory";
  299.                         }
  300.                     } else {
  301.                         badopt = 1;
  302.                     }
  303.                     break;
  304.                 
  305.                 case 'k':
  306.                     /* check for -k (MPW C) */
  307.                     if (arg[2] == '/0')
  308.                     {
  309.                         warn_not_implemented(arg);
  310.                         if (argv[i+1] != '-')    /* directory name to go along with -k */
  311.                             i++;
  312.                     }
  313.                             
  314.                     /* check for -kon (equiv to -opt branch) */
  315.                     else if (strcmp(arg, "-kon") == 0)
  316.                         make_short = 1;
  317.                     else
  318.                         badopt = 1;
  319.                         break;
  320.                 
  321.                 case 'm':
  322.                     /*Check for -m(mpwc)*/
  323.                     if (arg[2] == '\0') {
  324.                         /*Translate into gcc lingo*/
  325.                         strcat(cc1_options, " -mm");
  326.                         if (!got_mc68020 && !got_mc68040) {
  327.                             strcat(cpp_options, " -Dmc68020");
  328.                             strcat(cc1_options, " -m68020");
  329.                             got_mc68020 = 1;
  330.                           warn_dash_m_flag = 1;
  331.                         }
  332.                     
  333.                     /*Check for makedep(custom)*/
  334.                     } else if (strcmp(arg, "-makedep") == 0) {
  335.                         /*Translate*/
  336.                         strcat(cpp_options, " -M");
  337.                         run_cc1 = 0;
  338.                     
  339.                     /*Check for -mbg(mpwc)*/
  340.                     } else if (strcmp(arg, "-mbg") == 0) {
  341.                         /*Make sure there is another argument*/
  342.                         if (++i<argc) {
  343.                             
  344.                             /*Check for off*/
  345.                             if (strcmp(argv[i], "off") == 0) {
  346.                                 strcat(cc1_options, " -mbgoff -fomit-frame-pointer");
  347.                             
  348.                             /*Check for full*/
  349.                             } else if (strcmp(argv[i], "full") == 0) {
  350.                                 /*Default*/
  351.                                 
  352.                             /*Check for on*/
  353.                             } else if (strcmp(argv[i], "on") == 0) {
  354.                                 fprintf (stderr, "# Warning: -mbg on is not supported, try -mbg full.\n");
  355.                             
  356.                             /*Unknown option*/
  357.                             } else {
  358.                                 missing = "on|full";
  359.                             }
  360.                         } else {
  361.                             missing = "on|full";
  362.                         }
  363.                     
  364.                     /*Check for -mc68020(mpwc)*/
  365.                     } else if (strcmp(arg, "-mc68020") == 0) {
  366.                         warn_dash_m_flag = 0;
  367.                         /*Add in options if needed*/
  368.                         if (got_mc68020 == 0) {
  369.                             strcat(cpp_options, " -Dmc68020");
  370.                             strcat(cc1_options, " -m68020");
  371.                             got_mc68020 = 1;
  372.                         }
  373.                     
  374.                     } else if (strcmp(arg, "-mc68040") == 0) {
  375.                         warn_dash_m_flag = 0;
  376.                         /*Add in options if needed*/
  377.                         if (got_mc68040 == 0) {
  378.                             strcat(cpp_options, " -Dmc68040");
  379.                             strcat(cc1_options, " -m68040");
  380.                             got_mc68040 = 1;
  381.                         }
  382.                     
  383.                     /*Check for -mc68881(mpwc)*/
  384.                     } else if (strcmp(arg, "-mc68881") == 0) {
  385.                         strcat(cpp_options, " -Dmc68881");
  386.                         strcat(cc1_options, " -m68881");
  387.                     
  388.                     /*Check for -mnoseg(custom)*/
  389.                     } else if (strcmp(arg, "-mnoseg") == 0) {
  390.                         strcat(cc1_options, " -mnoseg");
  391.                     
  392.                     /*Check for -model(mpwc)*/
  393.                     } else if (strcmp(arg, "-model") == 0) {
  394.                         if (++i < argc) {
  395.                             /* get the next arg */
  396.                             arg = argv[i];
  397.                             /*Check for near*/
  398.                             if (strcmp(arg, "near") == 0) {
  399.                                 warn_not_implemented("-model near");
  400.                             
  401.                             /*Check for far*/
  402.                             } else if (strcmp(arg, "far") == 0) {
  403.                                 warn_not_implemented("-model far");
  404.                             
  405.                             /*Check for nearData*/
  406.                             } else if (strcmp(arg, "nearData") == 0) {
  407.                                 warn_not_implemented("-model nearData");
  408.                             
  409.                             /*Check for farData*/
  410.                             } else if (strcmp(arg, "farData") == 0) {
  411.                                 warn_not_implemented("-model farData");
  412.                             
  413.                             /*Check for nearCode*/
  414.                             } else if (strcmp(arg, "nearCode") == 0) {
  415.                                 warn_not_implemented("-model nearCode");
  416.                             
  417.                             /*Check for farCode*/
  418.                             } else if (strcmp(arg, "farCode") == 0) {
  419.                                 warn_not_implemented("-model farCode");
  420.                             
  421.                             /*Unknown options*/
  422.                             } else {
  423.                                 missing = "near|far|nearData|farData|nearCode|farCode";
  424.                             }
  425.                             
  426.                         /*Unknown option*/
  427.                         } else {
  428.                             missing = "near|far|nearData|farData|nearCode|farCode";
  429.                         }
  430.                   } else {
  431.                         /* pass it on to cc1 and let it analyze */
  432.                         strcat(cc1_options, " ");
  433.                         strcat(cc1_options, arg);
  434.                     }
  435.                     break;
  436.                     
  437.                 case 'n':
  438.                     if (!strcmp(arg, "-noext")) {
  439.                         target_name = "";
  440.  
  441.                     } else if (!strcmp(arg, "-nocpp")) {
  442.                         run_cpp = 0;
  443.  
  444.                     /*Check for -n(mpwc)*/
  445.                     } else if (arg[2] == '\0') {
  446.                         /* This is the default for GCC, so can ignore. */
  447.                     /*Unknown option*/
  448.                     } else {
  449.                         badopt = 1;
  450.                     }
  451.                     break;
  452.                     
  453.                 case 'o':
  454.                     /*Check for -opt(mpwc)*/
  455.                     if (strcmp(arg, "-opt") == 0) {
  456.                         /*Make sure we have enough arguments left*/
  457.                         if (++i<argc) {
  458.                             HandleOptOpts(argv[i]);
  459.                         
  460.                         /*Not enough arguments*/
  461.                         } else {
  462.                             missing = "on|off|full|branch";
  463.                         }
  464.                     
  465.                     /*Check for -o objname(mpwc)*/
  466.                     } else if (arg[2] == '\0') {
  467.                         /*Make sure we have enough arguments*/
  468.                         if (++i<argc) {
  469.                             output_filename = argv[i];
  470.                         
  471.                         /*Not enough arguments*/
  472.                         } else {
  473.                             missing = "output filename";
  474.                         }
  475.                     
  476.                     /*Unknown option*/
  477.                     } else {
  478.                         badopt = 1;
  479.                     }
  480.                     break;
  481.     
  482.                 case 'O':
  483.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  484.                         break;
  485.                     
  486.                 case 'p':
  487.                     /*Check for -p(mpwc)*/
  488.                     if (arg[2] == '\0') {
  489.                         /*Translate into gcc args*/
  490.                         strcat(cpp_options, " -v");
  491.                         strcat(cc1_options, " -version");
  492.                         quiet_flag = 0;
  493.                         strcat(asm_options, " -p");
  494.                         echo_cmds = 1;
  495.                     
  496.                     /*Check for -pedantic(gcc)*/
  497.                     } else if (strncmp(arg, "-pedantic", 9) == 0) {
  498.                         strcat(cpp_options, " ");  strcat(cpp_options, arg);
  499.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  500.                     
  501.                     /*Unkown option*/
  502.                     } else {
  503.                         badopt = 1;
  504.                     }
  505.                     break;
  506.                     
  507.                 case 'r':
  508.                     /*Check for -r(mpwc)*/
  509.                     if (arg[2] == '\0') {
  510.                         strcat(cc1_options, " -Wimplicit");
  511.                     
  512.                     /*Unkown*/
  513.                     } else {
  514.                         badopt = 1;
  515.                     }
  516.                     break;
  517.                     
  518.                 case 's':
  519.                     /*check for -s segment(mpwc)*/
  520.                     if (arg[2] == '\0') {
  521.                         /*Make sure we have enough options*/
  522.                         if (++i<argc) {
  523.                             strcat(cc1_options, " -s '");
  524.                             strcat(cc1_options, argv[i]);
  525.                             strcat(cc1_options, "'");
  526.                         } else {
  527.                             missing = "segment name";
  528.                         }
  529.                     }
  530.                     
  531.                     /*Check for -sym(mpwc)*/
  532.                     else if (strcmp(arg, "-sym") == 0) {
  533.                         /*Make sure we have enough args*/
  534.                         if (++i<argc) {
  535.                             if ((strcmp(argv[i], "full") == 0) || (strcmp(argv[i], "on") == 0)) {
  536.                                 if (HandleSymOpts(argv[i+1])) {
  537.                                     i++;
  538.                                 }
  539.                                 strcat(asm_options, " -sym ");  strcat(asm_options, argv[i]);
  540.                                 fprintf (stderr, "# Warning: symbolic info will be produced by assembler.\n");
  541.                             } else if (strcmp(argv[i], "off") == 0) {
  542.                                 /*default*/
  543.                             } else {
  544.                                 missing = "on|off|full";
  545.                             }
  546.                         } else {
  547.                             missing = "option";
  548.                         }
  549.                     
  550.                     /*Unknown option*/
  551.                     } else {
  552.                         badopt = 1;
  553.                     }
  554.                     break;
  555.                     
  556.                 case 't':
  557.                     /*Check for -t(mpwc)*/
  558.                     if (arg[2] == '\0') {
  559.                         quiet_flag = 0;
  560.                         strcat(asm_options, " -t");
  561.                     
  562.                     /*Check for -talk* */
  563.                     } else if (strncmp(arg, "-talk", 5) == 0) {
  564.                         strcat(cpp_options, " ");  strcat(cpp_options, arg);
  565.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  566.                         
  567.                     /*Check for -target(custom)*/
  568.                     } else if (strcmp(arg, "-target") == 0) {
  569.                         /*Make sure there are enough args*/
  570.                         if (++i<argc) {
  571.                             target_name = argv[i];
  572.                         } else {
  573.                             missing = "target machine";
  574.                         }
  575.                         
  576.                     /*Check for -traditional(gcc)*/
  577.                     } else if (strcmp(arg, "-traditional") == 0) {
  578.                         strcat(cpp_options, " -traditional");
  579.                         strcat(cc1_options, " -traditional");
  580.                         
  581.                     /*Check for tools(custom)*/
  582.                     } else if (strcmp(arg, "-tools") == 0) {
  583.                         /*Make sure there are enough args*/
  584.                         if (++i<argc) {
  585.                             tool_place = argv[i];
  586.                         } else {
  587.                             missing = "directory";
  588.                         }
  589.                     
  590.                     /*Check for -trace(mpwc)*/
  591.                     } else if (strcmp(arg, "-trace") == 0) {
  592.                         /*Make sure there are enough args*/
  593.                         if (++i<argc) {
  594.                             /*Check for on*/
  595.                             if (strcmp(argv[i], "on") == 0) {
  596.                                 strcat(cc1_options, " -trace on");
  597.                             
  598.                             /*Check for off*/
  599.                             } else if (strcmp(argv[i], "off") == 0) {
  600.                                 strcat(cc1_options, " -trace off");
  601.                             
  602.                             /*Check for always*/
  603.                             } else if (strcmp(argv[i], "always") == 0) {
  604.                                 strcat(cc1_options, " -trace always");
  605.                             
  606.                             /*Check for never*/
  607.                             } else if (strcmp(argv[i], "never") == 0) {
  608.                                 strcat(cc1_options, " -trace never");
  609.                             
  610.                             /*Unknown option*/
  611.                             } else {
  612.                                 missing = "on|off|always|never";
  613.                             }
  614.                         
  615.                         /*Unknown option*/
  616.                         } else {
  617.                             missing = "on|off|always|never";
  618.                         }
  619.                     
  620.                     /*Unknown option*/
  621.                     } else {
  622.                         badopt = 1;
  623.                     }
  624.                     break;
  625.                 
  626.                 case 'u':
  627.                     /*check for -u(mpwc)*/
  628.                     if (arg[2] == '\0') {
  629.                         /*Make sure there are enough args*/
  630.                         if (++i<argc) {
  631.                             /*Translate into gcc*/
  632.                             strcat(cpp_options, " -U");  strcat(cpp_options, argv[i]);
  633.                         
  634.                         /*Not enough args*/
  635.                         } else {
  636.                             missing = "symbol";
  637.                         }
  638.                         
  639.                     /*Unknown option*/
  640.                     } else {
  641.                         badopt = 1;
  642.                     }
  643.                     break;
  644.                     
  645.                 case 'w':
  646.                     /*Check for -w(mpwc)*/
  647.                     if (arg[2] == '\0') {
  648.                         strcat(cc1_options, " -w");
  649.                     
  650.                     /*Check for -w2(mpwc)*/
  651.                     } else if (arg[2] == '2' && arg[3] == '\0') {
  652.                         strcat(cc1_options, " -Wall");
  653.                     
  654.                     /*Check for -warnings(mpwc)*/
  655.                     } else if (strcmp(arg, "-warnings") == 0) {
  656.                         /*Make sure there are enough args*/
  657.                         if (++i<argc) {
  658.                             
  659.                             /*Check for on*/
  660.                             if (strcmp(argv[i], "on") == 0) {
  661.                                 strcat(cc1_options, " -Wall");
  662.                             
  663.                             /*Check for full*/
  664.                             } else if (strcmp(argv[i], "full") == 0) {
  665.                                 strcat(cc1_options, " -Wall");
  666.                             
  667.                             /*Check for off*/
  668.                             } else if (strcmp(argv[i], "off") == 0) {
  669.                                 strcat(cc1_options, " -w");
  670.                             
  671.                             /*Unknown option*/
  672.                             } else {
  673.                                 missing = "on|off|full";
  674.                             }
  675.  
  676.                         /*Unknown option*/
  677.                         } else {
  678.                             missing = "on|off|full";
  679.                         }
  680.                     
  681.                     /*Unknown option*/
  682.                     } else {
  683.                         badopt = 1;
  684.                     }
  685.                     break;
  686.                 
  687.                 case 'W':
  688.                     /*Check for -W(gcc)*/
  689.                     if (arg[2] == '\0') {
  690.                         strcat(cc1_options, " -W");
  691.                     
  692.                     /*Check for -Wall(gcc)*/
  693.                     } else if (strcmp(arg, "-Wall") == 0) {
  694.                         strcat(cc1_options, " -Wall");
  695.                     
  696.                     /*Check for a slew of gcc options*/
  697.                     } else if (arg[2] != '\0') {
  698.                         /* pass it to cc1 and let it complain */
  699.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  700.                     } else {
  701.                         badopt = 1;
  702.                     }
  703.                     break;
  704.                 
  705.                 case 'X':
  706.                     if (strlen(arg) >= 3 && arg[3] == ',') {
  707.                         switch (arg[2]) {
  708.                             case 'p':
  709.                                 strcat(cpp_options, " ");  strcat(cpp_options, arg + 4);
  710.                                 break;
  711.                             case 'c':
  712.                                 strcat(cc1_options, " ");  strcat(cc1_options, arg + 4);
  713.                                 break;
  714.                             case 'a':
  715.                                 strcat(asm_options, " ");  strcat(asm_options, arg + 4);
  716.                                 break;
  717.                         }
  718.                   }
  719.                     break;
  720.  
  721.                 case 'y':
  722.                     /*Check for -y(mpwc)*/
  723.                     if (arg[2] == '\0') {
  724.                         if (++i<argc) {
  725.                             tmp = argv[i];
  726.                         } else {
  727.                             missing = "directory";
  728.                         }
  729.                     } else {
  730.                         badopt = 1;
  731.                     }
  732.                     break;
  733.     
  734.                 default:
  735.                     badopt = 1;
  736.             }
  737.             
  738.             if (missing[0] != '\0') {
  739.                 fprintf (stderr, "# Warning: missing %s after \"%s\".\n", missing, arg1);
  740.             } else if (badopt) {
  741.                 fprintf (stderr, "# Warning: invalid option %s ignored.\n", arg);
  742.             }
  743.         
  744.         /*Check for filename*/
  745.         } else if (input_filename[0] == '\0') {
  746.             input_filename = arg;
  747.         
  748.         /*Extra file names is a no no*/
  749.         } else {
  750.             fprintf (stderr, "# Warning: extra input filename %s ignored.\n", arg);
  751.         }
  752.     }
  753.     
  754.     /*Not enough filenames is a no no*/
  755.     if (input_filename[0] == '\0') {
  756.         fprintf (stderr, "# Error: no input filename.\n");
  757.         exit(2);
  758.     }
  759.  
  760.     if (strcmp(target_name, "Mac68K") == 0
  761.           || strcmp(target_name, "68k") == 0) {
  762.       target_name = "Mac68K";
  763.         asm_tool_name = "Asm";
  764.     } else if (strcmp(target_name, "PowerPC") == 0) {
  765.         asm_tool_name = "PowerPCAsm";
  766.     } else {
  767.         asm_tool_name = "XXX_Asm";
  768.     }
  769.     strcpy(tmp_filename, tmp);
  770.     if ( (basename = strrchr(input_filename, ':')) != NULL)
  771.         ++basename;
  772.     else
  773.       basename = input_filename;
  774.     strcat(tmp_filename, basename);
  775.     
  776.     if (run_cc1) {
  777.         strcpy(cpp_filename, tmp_filename);
  778.         strcat(cpp_filename, "._");
  779.     }
  780.     
  781.     strcpy(asm_filename, tmp_filename);
  782.     strcat(asm_filename, ".a");
  783.     
  784.     if (output_filename[0] == '\0') {
  785.         strcpy(out_filename, input_filename);
  786.         strcat(out_filename, ".o");
  787.         output_filename = out_filename;
  788.     }
  789.     else if (output_filename[strlen(output_filename)-1] == ':') { // it's a directory, copy basename so we get .c.o 
  790.         strcpy(out_filename, output_filename);                                          // not .c.a.o
  791.         strcat(out_filename, basename);                                                            
  792.         strcat(out_filename, ".o");
  793.         output_filename = out_filename;
  794.     }
  795.         
  796.     if (quiet_flag)
  797.         strcat(cc1_options, " -quiet");
  798.         
  799.     if (optimize)
  800.         strcat(cc1_options, " -O");
  801.     else if (optimize >= 2)
  802.         strcat(cc1_options, " -O2");
  803.  
  804.     if (warn_dash_m_flag)
  805.       fprintf (stderr, "# Warning: -m forces -mc68020\n");
  806.         
  807.     printf ("set oldexit {exit}\n");
  808.     printf ("set exit 0\n");
  809.             
  810.     if (run_cpp) {
  811.         if (echo_cmds)
  812.             printf ("\techo \"'%s'cpp_%s %s '%s' '%s'\"\n", tool_place, target_name, cpp_options, input_filename, cpp_filename);
  813.         printf (           "'%s'cpp_%s %s '%s' '%s'\n",   tool_place, target_name, cpp_options, input_filename, cpp_filename);
  814.         printf ("if {status} == 0\n");
  815.     }
  816.         
  817.     if (run_cc1) {
  818.         if (echo_cmds)
  819.             printf ("\techo \"'%s'cc1_%s %s '%s' -o '%s' -dumpbase '%s'\"\n", tool_place, target_name, cc1_options, cpp_filename, asm_filename, tmp_filename);
  820.         printf (         "\t'%s'cc1_%s %s '%s' -o '%s' -dumpbase '%s'\n",   tool_place, target_name, cc1_options, cpp_filename, asm_filename, tmp_filename);
  821.         printf ("\tif {status} == 0\n");
  822.         if (!debug_gcc && run_cpp) {
  823.             printf ("\t\tdelete -i -y '%s'\n", cpp_filename);
  824.         }
  825.         
  826.         if (run_asm) {
  827.             if (make_short) {
  828.                 if (echo_cmds)
  829.                     printf ("\t\techo \"%s %s '%s' -o '%s' ∑ '%s'\"\n", asm_tool_name, asm_options, asm_filename, output_filename, shorten_filename);
  830.                 printf ("\t\techo -n > '%s'\n", shorten_filename);
  831.                 printf (         "\t\t%s %s '%s' -o '%s' ∑ '%s'\n",   asm_tool_name, asm_options, asm_filename, output_filename, shorten_filename);
  832.                 printf ("\t\tif {status} != 0\n");
  833.               printf ("\t\t\tcatenate '%s' >> Dev:StdErr\n", shorten_filename);
  834.               printf ("\t\t\tset exit {oldexit}\n");
  835.               printf ("\t\t\texit 2\n");
  836.               printf ("\t\tend\n");
  837.                 printf ("\t\tloop\n");
  838.                 if (echo_cmds)
  839.                   printf ("\t\t\techo \"Search -sf /•### Warning 210/ '%s' >> dev:null\"\n", shorten_filename);
  840.                 printf (         "\t\t\tSearch -sf /•### Warning 210/ '%s' >> dev:null\n",   shorten_filename);
  841.                 printf ("\t\t\tif {status} == 0\n");
  842.                 if (echo_cmds)
  843.                     printf ("\t\t\t\techo \"'%s'shorten -a '%s' -e '%s' -o '%s'\"\n", tool_place, asm_filename, shorten_filename, shorten_out_filename);
  844.                 printf (         "\t\t\t\t'%s'shorten -a '%s' -e '%s' -o '%s'\n",   tool_place, asm_filename, shorten_filename, shorten_out_filename);
  845.                 if (echo_cmds)
  846.                   printf ("\t\t\t\techo \"move -y '%s' '%s'\"\n", shorten_out_filename, asm_filename);
  847.                 printf (         "\t\t\t\tmove -y '%s' '%s'\n",   shorten_out_filename, asm_filename);
  848.                 if (echo_cmds)
  849.                     printf ("\t\t\t\techo \"%s %s '%s' -o '%s' ∑ '%s'\"\n", asm_tool_name, asm_options, asm_filename, output_filename, shorten_filename);
  850.                 printf (         "\t\t\t\t%s %s '%s' -o '%s' ∑ '%s'\n",   asm_tool_name, asm_options, asm_filename, output_filename, shorten_filename);
  851.                 printf ("\t\t\telse\n");
  852.                 if (!debug_gcc)
  853.                 {
  854.                     printf ("\t\t\t\tdelete -i -y '%s'\n", shorten_filename);
  855.                     printf ("\t\t\t\tdelete -i -y '%s'\n", shorten_out_filename);
  856.                 }
  857.                 printf ("\t\t\t\tbreak\n");
  858.                 printf ("\t\t\tend\n");
  859.                 printf ("\t\tend\n");
  860.             }
  861.             else
  862.             {
  863.                 if (echo_cmds)
  864.                     printf ("\t\techo \"%s -w %s '%s' -o '%s'\"\n", asm_tool_name, asm_options, asm_filename, output_filename);
  865.                 printf (         "\t\t%s -w %s '%s' -o '%s'\n",   asm_tool_name, asm_options, asm_filename, output_filename);
  866.             }
  867.             printf ("\t\tif {status} == 0\n");
  868.             if (!debug_gcc)
  869.                 printf ("\t\t\tdelete -i -y '%s'\n", asm_filename);
  870.             printf ("\t\telse\n");
  871.             printf ("\t\t\tset exit {oldexit}\n");
  872.             printf ("\t\t\texit 2\n");
  873.             printf ("\t\tend\n");
  874.         }
  875.         printf ("\telse\n");
  876.         if (!debug_gcc) {
  877.             if (run_cpp)
  878.                 printf ("\t\tdelete -i -y '%s'\n", cpp_filename);
  879.             printf ("\t\tdelete -i -y '%s'\n", asm_filename);
  880.         }
  881.         printf ("\t\tset exit {oldexit}\n");
  882.         printf ("\t\texit 2\n");
  883.         printf ("\tend\n");
  884.         
  885.     }
  886.     printf ("else\n");
  887.     if (!debug_gcc) {
  888.         printf ("\tdelete -i -y '%s'\n", cpp_filename);
  889.     }
  890.     printf ("\tset exit {oldexit}\n");
  891.     printf ("\texit 2\n");
  892.     printf ("end\n");
  893.     
  894. /*    if (echo_cmds)*/
  895. /*        printf ("set echo {oldecho}\n");*/
  896.     printf ("set exit {oldexit}\n");
  897.     
  898.     exit(0);
  899. }
  900.  
  901. warn_not_implemented(arg)
  902. char *arg;
  903. {
  904.   fprintf (stderr, "# Warning: %s ignored, not implemented yet.\n", arg);
  905. }
  906.  
  907. escape_single_quotes(buf)
  908. char *buf;
  909. {
  910.     int i, j;
  911.     
  912.     for (i = 0; buf[i] != '\0'; ++i) {
  913.         if (buf[i] == '\'') {
  914.           buf[strlen(buf)+1] = '\0';
  915.             for (j = strlen(buf)+1; j > i; --j) {
  916.                 buf[j] = buf[j-1];
  917.           }
  918.           buf[i++] = '∂';
  919.         }
  920.     }
  921. }
  922.